package com.yiwenup.common.basic;

import com.yiwenup.common.enums.RespMsgEnum;
import com.yiwenup.common.enums.RespTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;

/**
 * 抽象响应对象
 **/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class BaseResponseDTO<T> implements Serializable {
    private static final long serialVersionUID = 1367941646357704619L;

    /**
     * 响应状态
     */
    private String respType;

    /**
     * 响应码
     */
    private String respCode;

    /**
     * 响应信息
     */
    private String respMsg;

    /**
     * 响应数据
     */
    private T data;

    /**
     * 响应成功
     *
     * @param respMsgEnum 成功信息
     * @param data        数据
     * @param <T>         数据类型
     * @return 响应成功封装
     */
    public static <T> BaseResponseDTO<T> ok(RespMsgEnum respMsgEnum, T data) {
        return new BaseResponseDTO<>(RespTypeEnum.RESP_SUCCESS.getCode(), respMsgEnum.getCode(),
                respMsgEnum.getDesc(), data);
    }

    /**
     * 响应成功
     *
     * @param respMsgEnum 成功信息
     * @return 响应成功封装
     */
    public static BaseResponseDTO<Object> ok(RespMsgEnum respMsgEnum) {
        return new BaseResponseDTO<>(RespTypeEnum.RESP_SUCCESS.getCode(), respMsgEnum.getCode(),
                respMsgEnum.getDesc(), null);
    }

    /**
     * 响应成功
     *
     * @return 响应成功封装
     */
    public static BaseResponseDTO<Object> ok() {
        return new BaseResponseDTO<>(RespTypeEnum.RESP_SUCCESS.getCode(), RespMsgEnum.SUCCESS.getCode(),
                RespMsgEnum.SUCCESS.getDesc(), null);
    }

    /**
     * 响应失败
     *
     * @return 响应失败封装
     */
    public static BaseResponseDTO<Object> fail() {
        return new BaseResponseDTO<>(RespTypeEnum.RESP_FAILURE.getCode(), null, null, null);
    }
}
